package com.ruoyi.wb.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.wb.domain.WbMaintainCompany;
import com.ruoyi.wb.domain.WbStatistics;
import com.ruoyi.wb.mapper.WbMaintainCompanyMapper;
import com.ruoyi.wb.mapper.WbStatisticsMapper;
import com.ruoyi.wb.service.IWbStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;


@Service
public class WbStatisticsServiceImpl implements IWbStatisticsService {

    @Autowired
    WbStatisticsMapper wbStatisticsMapper;

    //查询维保公司
    @Autowired
    WbMaintainCompanyMapper wbMaintainCompanyMapper;

    @Override
    public WbStatistics count() {
        Long userId = SecurityUtils.getUserId();
        List<WbMaintainCompany> wbMaintainCompanies = wbMaintainCompanyMapper.selectWbMaintainCompanyByUserId(userId);
        if (!CollectionUtils.isEmpty(wbMaintainCompanies)){
            WbStatistics count = wbStatisticsMapper.count(wbMaintainCompanies.get(0).getId());
            count.setIfShow(false);
            return count;
        }
        WbStatistics count = wbStatisticsMapper.count(null);
        count.setIfShow(true);
        return count;
    }
}
